package com.kaigejava.webmaginc;


import us.codecraft.webmagic.Page;
import us.codecraft.webmagic.Site;
import us.codecraft.webmagic.Spider;
import us.codecraft.webmagic.processor.PageProcessor;

/**
 * 简单demo1
 * @author kaigejava
 */
public class SimpleDemo3 implements PageProcessor {

    public void process(Page page) {
        //将当前页面 里的所有链接都添加到目标页面中
        page.addTargetRequests( page.getHtml().links().all() );
        System.out.println(page.getHtml().xpath("//* [@id=\"nav\"]/div/div/ul/li[5]/a").toString());
    }

    public Site getSite() {
        return Site.me().setSleepTime(100).setRetryTimes(3);
    }

    public static void main(String[] args) {
        Spider.create(new SimpleDemo3()).addUrl("https://blog.csdn.net/").run();
    }
}
